package com.zenithmind.disk.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 分享可见性枚举
 * 遵循开闭原则：新增可见性类型时只需添加枚举值
 */
@Getter
@AllArgsConstructor
public enum ShareVisibility {
    
    /**
     * 私密分享
     */
    PRIVATE(0, "私密分享"),
    
    /**
     * 公开分享
     */
    PUBLIC(1, "公开分享");
    
    private final Integer code;
    private final String description;
    
    /**
     * 根据代码获取枚举
     * @param code 可见性代码
     * @return 对应的枚举值
     */
    public static ShareVisibility fromCode(Integer code) {
        if (code == null) {
            return null;
        }
        
        for (ShareVisibility visibility : values()) {
            if (visibility.code.equals(code)) {
                return visibility;
            }
        }
        
        throw new IllegalArgumentException("未知的分享可见性代码: " + code);
    }
    
    /**
     * 检查是否为公开分享
     * @return true如果是公开分享
     */
    public boolean isPublic() {
        return this == PUBLIC;
    }
    
    /**
     * 检查是否为私密分享
     * @return true如果是私密分享
     */
    public boolean isPrivate() {
        return this == PRIVATE;
    }
}
